<html>
<body>
<pre>
Overview

The library deals with these concepts:

    * Widget — A class that corresponds to an HTML form widget, e.g. <input type="text"> or <textarea>. This handles rendering of the widget as HTML.
    * Field — A class that is responsible for doing validation, e.g. an EmailField that makes sure its data is a valid e-mail address.
    * Form — A collection of fields that knows how to validate itself and display itself as HTML.

Form objects

The primary way of using the forms library is to create a form object. Do this by subclassing BaseForm and specifying the form’s fields, in a declarative style that you’ll be familiar with if you’ve used Django database models. In this section, we’ll iteratively develop a form object that you might use to implement “contact me” functionality on your personal Web site.

Start with this basic Form subclass, which we’ll call ContactForm:

import org.hibernate.validator.*;
import javango.forms.*;

public static class ContactForm extends BaseForm {

	@Length(max = 100)
	public Field subject = new CharField();		
    public Field message = new CharField();
    public Field sender = new EmailField();	    
    public Field ccMyself = new BooleanField().setRequired(false);
    public Field value = new IntegerField();


A form is composed of Field objects. In this case, our form has four fields: subject, message, sender and ccMyself. We’ll explain the different types of fields — e.g., CharField and EmailField — shortly.

Creating a new Form

Create an unbound form

Form f = new ContactForm();

Create a bound form

Map m = new HashMap();
m.put("subject", "Hello World");
Form f = new ContactForm(m);

</pre>
</body>
</html>